package my2Cents.tools;

import java.awt.Graphics2D;
import java.awt.event.MouseEvent;

import my2Cents.Sandbox;
import my2Cents.Util;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.PCircle;

public class CircleTool extends AbstractBodyMaker {
	private float size;
	
	public CircleTool() {
		thinkDelay = false;
		setName("Circle");
		setDescription(
				"Click and drag to create a Circle."
			);
	}
	
	public void startTool(MouseEvent arg0) {
		super.startTool(arg0);
		size = 0;
	}
	
	public void toolThink(MouseEvent arg0) {
		super.toolThink(arg0);
		Vector2f vec = new Vector2f(arg0.getX(), arg0.getY());
		size = shapePos.distance(vec);
		shapeAngle = (float) Util.angleVec(shapePos, vec);
		shape = new PCircle(size);
	}
	
	public void endTool(MouseEvent arg0) {
		if(size > 0) {
			Body b = createBody(size*2);
			b.setPosition(shapePos.x, shapePos.y);
			b.setRotation(shapeAngle);
			sandbox.postBodyCreated(b);
		}
		super.endTool(arg0);
	}
}
